/**
* @filename:${controllerName} ${createTime}
* @project ${project}  ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${controllerUrl};

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

<#list pkgs as ps>
    <#if ps??>
			import ${ps};
    </#if>
</#list>

/**
* @Description: ${entityComment}Controller
*
* @version: ${version}
* @author: ${author}
*
*/
@Slf4j
@RestController
@RequestMapping("/${lowerEntityName}")
public class ${controllerName} {
	@Autowired
	${serviceName} service;

	@RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
	public BaseMode add(@RequestBody ${entityName} obj) {
		try {
			service.add(obj);
			return ModeView.bulid(true, "成功！");
		} catch (HintException e) {
			log.error(PUtils.excepitonToString(e));
			return ModeView.bulid(false, "失败！");
		}
	}

	@RequestMapping(value = "/delete", method = {RequestMethod.GET, RequestMethod.POST})
	public BaseMode delete(int id) {
		try {
			service.delete(id);
			return ModeView.bulid(true, "成功！");
		} catch (HintException e) {
			log.error(PUtils.excepitonToString(e));
			return ModeView.bulid(false, "失败！");
		}
	}

	@RequestMapping(value = "/update", method = {RequestMethod.GET, RequestMethod.POST})
	public BaseMode update(@RequestBody ${entityName} obj) {
		try {
			service.update(obj);
			return ModeView.bulid(true, "成功！");
		} catch (HintException e) {
			log.error(PUtils.excepitonToString(e));
			return ModeView.bulid(false, "失败！");
		}
	}


	@RequestMapping(value = "/select", method = {RequestMethod.GET, RequestMethod.POST})
	public BaseMode select(<#list cis as ci>${ci.javaType} ${ci.property},</#list>Integer start,Integer limit) {
		try {
			Map<String, Object> filter = PUtils.initFilter(start, limit);
		<#list cis as ci1>
			if (!PUtils.isEmpty(${ci1.property})) filter.put("${ci1.property}", ${ci1.property});
		</#list>
			return ModeBean.bulid(true, "成功！", serivce.getList(filter)).createTotal(service.count(filter));
		} catch (HintException e) {
			log.error(PUtils.excepitonToString(e));
			return ModeView.bulid(false, "失败！");
		}
	}


}
	